<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.prime.com.tr/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets"

>
<f:view locale="#{LangBean.currentLocale}"></f:view>
<ui:composition template="/template_default.xhtml">	
<ui:define name="main">
                 <h:form prependId="false">
                    <p:commandButton value="#{lang.novasaida}" actionListener="#{saidaBean.create}" update="infosSaida, total, gridProduto" oncomplete="dialogSaida.show()"/>
                </h:form>
		<h:form prependId="false">
		<p:dataTable id="gridSaida" var="out" value="#{saidaBean.saidas}" paginator="true" rows="5">
			<p:column>
				<f:facet name="header">
					<h:outputText value="ID"/>
				</f:facet>
				<h:outputText value="#{out.id}"/>
			</p:column>
			<p:column>
				<f:facet name="header">
					<h:outputText value="#{lang.cliente}"/>
				</f:facet>
				<h:outputText value="#{out.cliente.nome}"/>
			</p:column>
			<p:column>
				<f:facet name="header">
					<h:outputText value="#{lang.total}"/>
				</f:facet>
				<h:outputText value="#{out.totalSaida}"/>
			</p:column>

			<p:column>
				<f:facet name="header">
					<h:outputText value="#{lang.opcoes}"/>
				</f:facet>
						<p:commandButton value="#{lang.alterar}" actionListener="#{saidaBean.load}" update="infosSaida, total, gridProduto" oncomplete="dialogSaida.show()"/>
			</p:column>
		</p:dataTable>
		</h:form>
		
</ui:define>

<ui:define name="dialogs">

		<!-- DIALOG -->

<p:dialog header="#{lang.cad_produtos}" widgetVar="dialogSaida"  resizable="false" modal="true" showEffect="explode" hideEffect="explode" width="700">
            <h:form prependId="false">
                <h:panelGrid id="infosSaida" columns="2" style="margin-bottom:10px">
                    <h:outputText value="#{lang.datasaida}" />
                    <p:calendar id="dataSaida" value="#{saidaBean.saida.dataSaida}" />
                    <h:outputText value="#{lang.cliente}" />
			      	<h:selectOneMenu value="#{saidaBean.clienteSelecionado}">  
           				<f:selectItem itemLabel="#{lang.selecione}" itemValue="" />  
            			<f:selectItems value="#{saidaBean.listaClientes}"/>  
        			</h:selectOneMenu>                    
                </h:panelGrid>
                	
                	<p:panel header="#{lang.itens}">
	                 	<h:outputText value="#{lang.produtos}"/>
	               		<h:selectOneMenu value="#{saidaBean.produtoSelecionado}">  
	           				<f:selectItem itemLabel="#{lang.selecione}" itemValue="" />  
	            			<f:selectItems value="#{saidaBean.listaProdutos}"/>  
	        			</h:selectOneMenu>
	        			<h:outputText value="#{lang.quantidade}"/>
	        			<p:inputText id="quantidade" value="#{saidaBean.quantidade}" size="2"/>
	        			<p:commandButton update="gridProduto" actionListener="#{saidaBean.adicionarProduto}" value="+"/>
                	
					<h:form prependId="false">
						<p:dataTable id="gridProduto" var="itens" value="#{saidaBean.saida.itensSaida}">
							<p:column>
								<f:facet name="header">
									<h:outputText value="#{lang.descricao}"/>
								</f:facet>
							<h:outputText value="#{itens.produto.descricao}"/>
							</p:column>
							<p:column>
								<f:facet name="header">
									<h:outputText value="#{lang.quantidade}"/>
								</f:facet>
							<h:outputText value="#{itens.quantidade}"/>
							</p:column>
						</p:dataTable>
					</h:form>
					
					<h:panelGrid id="total" columns="2" style="margin:10px">
	                    <h:outputText value="#{lang.totalitens}" />
	                    <p:inputText id="totalitens" value="#{saidaBean.saida.totalItens}" readonly="true"/>
	                    <h:outputText value="#{lang.total}:" />
	                    <p:inputText id="totalsaida" value="#{saidaBean.saida.totalSaida}" readonly="true">
	                    	<f:convertNumber type="currency" />
	                    </p:inputText>
					</h:panelGrid>
                	</p:panel>
					

 					
 					<p:commandButton update="growl,gridSaida" oncomplete="dialogSaida.hide();" actionListener="#{saidaBean.salvar}" value="#{lang.inserir}"/>
                    <p:commandButton update="growl,gridSaida" oncomplete="dialogSaida.hide();" actionListener="#{saidaBean.update}" value="#{lang.alterar}"  />
            </h:form>
        </p:dialog>

</ui:define>


</ui:composition>
</html>